Vector¶

Vector is base class of other vector like classes. It represents a series of vectors.

In [1]:
from py3d import Vector
Vector()
Out[1]:
Vector([], dtype=float64)
In [3]:
Vector([0, 0, 0, 0])
Out[3]:
Vector([0, 0, 0, 0])
In [5]:
Vector([1, 2, -4])
Out[5]:
Vector([ 1,  2, -4])
In [7]:
Vector([1, 2, 3], (2,))
Out[7]:
Vector([[1, 2, 3],
        [1, 2, 3]])
In [9]:
import py3d
py3d.Vector([1, 2, 0, 3], ())
Out[9]:
Vector([1, 2, 0, 3])
In [10]:
Vector([1], (2,))
Out[10]:
Vector([[1],
        [1]])

Get unit vector

In [12]:
import py3d
V32 = py3d.Vector([
    [1, 3],
    [2, -9],
    [0.1, -3]])
V32

V32.U
Out[12]:
Vector([[ 0.31622777,  0.9486833 ],
        [ 0.21693046, -0.97618706],
        [ 0.03331483, -0.99944491]])

Get length of vectors

In [13]:
V32.L
Out[13]:
array([[3.16227766],
       [9.21954446],
       [3.0016662 ]])
In [15]:
from numpy import allclose
assert allclose(V32.U.L, [[1], [1], [1]])

Get homogeneous vector

In [16]:
V32.H
Out[16]:
Vector3([[ 1. ,  3. ,  1. ],
         [ 2. , -9. ,  1. ],
         [ 0.1, -3. ,  1. ]])

Get a series of random vectors

In [18]:
import py3d
py3d.Vector.Rand(2,3,4)
Out[18]:
Vector([[[0.43578129, 0.34575936, 0.70693258, 0.77517889],
         [0.90612068, 0.49931281, 0.28356419, 0.4466531 ],
         [0.7402473 , 0.91662313, 0.50333922, 0.61690147]],

        [[0.84025601, 0.98419091, 0.50377457, 0.013184  ],
         [0.58059916, 0.79023643, 0.98708413, 0.97517111],
         [0.80113453, 0.28171909, 0.91251944, 0.5252285 ]]])
In [20]:
import py3d
py3d.Vector([[0,0],[1,2],[3,4]]).diff()
Out[20]:
Vector([[1, 2],
        [2, 2]])

Read pcd file

In [22]:
import py3d

py3d.read_pcd("ascii.pcd").xyz.as_point()
Out[22]:
In [23]:
import py3d
pcd = py3d.read_pcd("binary.pcd")
pcd.xyz.as_point().paint(py3d.Color.map(pcd.intensity, 0, 255))
Out[23]: